import 字段包.UserBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//登录程序
@WebServlet(name = "LoginServlet",value = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userCode = request.getParameter("userCode");
        String userPassword = request.getParameter("userPassword");
        UserDao dao = new UserDao();
        UserBean user = dao.findByUserCode(userCode,userPassword);
        if (user == null){
            request.setAttribute("message","用户或密码错误");
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }else{
            request.setAttribute("user",user);
            request.getRequestDispatcher("/success.jsp").forward(request,response);
        }
    }
}
